package com.bit.cfdi.web.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.bit.cfdi.web.dao.ConceptoParteDAO;
import com.bit.cfdi.web.domain.ConceptoParte;

@Repository
public class ConceptoParteDAOImpl extends HibernateDaoSupport implements
		ConceptoParteDAO {

	@Autowired
	public void init(final SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}
	
	@Override
	@Transactional public void save(ConceptoParte concepto) throws DataAccessException  {
		getHibernateTemplate().saveOrUpdate(concepto);
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional public ConceptoParte getById(Long id) throws DataAccessException {
		List<ConceptoParte> conceptosPartes = getHibernateTemplate().find(
				" from ConceptoParte as cp" +
				" where cp.idConceptoParte=?", id);
		return conceptosPartes.size()>0?conceptosPartes.get(0):null;
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional public List<ConceptoParte> getAll() throws DataAccessException {
		List<ConceptoParte> conceptosPartes = getHibernateTemplate().find(
				" from ConceptoParte as cp");
		return conceptosPartes;
	}

}